package com.ruoyi.lab.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.lab.domain.LabSupplier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lab.domain.LabEquipment;
import com.ruoyi.lab.service.ILabEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author mojar
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/lab/equipment")
public class LabEquipmentController extends BaseController
{
    @Autowired
    private ILabEquipmentService labEquipmentService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('lab:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabEquipment labEquipment)
    {
        startPage();
        List<LabEquipment> list = labEquipmentService.queryList(labEquipment);
        return getDataTable(list);
    }

    /**
     * 查询所有设备列表
     */
    @GetMapping("listAll")
    public AjaxResult listAll(LabEquipment labEquipment){
        List<LabEquipment> list = labEquipmentService.queryList(labEquipment);
        return success(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('lab:equipment:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabEquipment labEquipment)
    {
        List<LabEquipment> list = labEquipmentService.queryList(labEquipment);
        ExcelUtil<LabEquipment> util = new ExcelUtil<>(LabEquipment.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(labEquipmentService.getById(id));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('lab:equipment:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabEquipment labEquipment)
    {
        return toAjax(labEquipmentService.save(labEquipment));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('lab:equipment:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabEquipment labEquipment)
    {
        return toAjax(labEquipmentService.updateById(labEquipment));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('lab:equipment:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(labEquipmentService.removeBatchByIds(ids));
    }
}
